﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.ComponentModel;
using System.Collections.Generic;
using System.Windows.Data;
using System.IO;
using System.Linq;

using Cinch;


namespace Anata.Client
{
    /// <summary>
    /// </summary>
    public class CabangThumbnailViewModel : ViewModelBase
    {
        #region Data

        //private ViewMode currentViewMode = ViewMode.AddMode;

        #region Data.Primitives
        private Int32 idCabang;
        private String nama;
        private String alamat;
        private Boolean isGudang = false;

        private bool isBusy = false;
        #endregion

        //private IEnumerable<DataWrapperBase> cachedListOfDataWrappers;

        #region Data.Rules
        #endregion

        #region Data.VMs
        private DispatcherNotifiedObservableCollection<CabangLayananThumbnailViewModel> cabangLayanans;
        private ICollectionView cabangLayanansCV;
        private DispatcherNotifiedObservableCollection<CabangProdukThumbnailViewModel> cabangProduks;
        private ICollectionView cabangProduksCV;
        private DispatcherNotifiedObservableCollection<PromoThumbnailViewModel> promos;
        private ICollectionView promosCV;
        private DispatcherNotifiedObservableCollection<FreeGiftThumbnailViewModel> freeGifts;
        private ICollectionView freeGiftsCV;
        private DispatcherNotifiedObservableCollection<AsetThumbnailViewModel> asets;
        private ICollectionView asetsCV;
        private DispatcherNotifiedObservableCollection<StokThumbnailViewModel> stoks;
        private ICollectionView stoksCV;
        #endregion

        #region Data.Services
        #endregion

        #endregion

        #region Constructor
        public CabangThumbnailViewModel()
        {
            #region Constructor.SetupServices
            #endregion

            #region Constructor.SetupCommands
            CabangRemoveCommand = new SimpleCommand<Object, Object>(CanExecuteCabangRemoveCommand, ExecuteCabangRemoveCommand);
            #endregion

            #region Constructor.SetupDataWrappers
            #endregion

            //fetch list of all DataWrappers, so they can be used again later without the
            //need for reflection
            //cachedListOfDataWrappers =
            //    DataWrapperHelper.GetWrapperProperties<CabangThumbnailViewModel>(this);

            #region Constructor.SetupValidationRules
            #endregion

            #region Constructor.SetupVMs
            CabangLayanans = new DispatcherNotifiedObservableCollection<CabangLayananThumbnailViewModel>();
            CabangLayanansCV = CollectionViewSource.GetDefaultView(cabangLayanans);
            ProdukCabangs = new DispatcherNotifiedObservableCollection<CabangProdukThumbnailViewModel>();
            CabangProduksCV = CollectionViewSource.GetDefaultView(cabangProduks);
            Promos = new DispatcherNotifiedObservableCollection<PromoThumbnailViewModel>();
            PromosCV = CollectionViewSource.GetDefaultView(promos);
            FreeGifts = new DispatcherNotifiedObservableCollection<FreeGiftThumbnailViewModel>();
            FreeGiftsCV = CollectionViewSource.GetDefaultView(freeGifts);
            #endregion

        }
        #endregion

        #region Static
        #endregion

        #region Public Properties
        #region Public.Commands
        public SimpleCommand<Object, Object> CabangRemoveCommand { get; private set; }
        #endregion

        #region Public.ViewMode
        #endregion

        #region Public.Data
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs idCabangChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.IdCabang);
        public Int32 IdCabang
        {
            get { return idCabang; }
            set
            {
                idCabang = value;
                NotifyPropertyChanged(idCabangChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs namaChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.Nama);
        public String Nama
        {
            get { return nama; }
            set
            {
                nama = value;
                NotifyPropertyChanged(namaChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs alamatChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.Alamat);
        public String Alamat
        {
            get { return alamat; }
            set
            {
                alamat = value;
                NotifyPropertyChanged(alamatChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs isGudangChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.IsGudang);
        public Boolean IsGudang
        {
            get { return isGudang; }
            set
            {
                isGudang = value;
                NotifyPropertyChanged(isGudangChangeArgs);
            }
        }
        #endregion

        #region Public.IsBusy
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs isBusyChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.IsBusy);
        public Boolean IsBusy
        {
            get { return isBusy; }
            set
            {
                isBusy = value;
                NotifyPropertyChanged(isBusyChangeArgs);
            }
        }
        #endregion

        #region Public.Cached Collection
        #endregion

        #region Public.DataVM
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs cabangLayanansChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.CabangLayanans);
        public DispatcherNotifiedObservableCollection<CabangLayananThumbnailViewModel> CabangLayanans
        {
            get { return cabangLayanans; }
            set
            {
                cabangLayanans = value;
                NotifyPropertyChanged(cabangLayanansChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs cabangLayanansCVChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.CabangLayanansCV);
        public ICollectionView CabangLayanansCV
        {
            get { return cabangLayanansCV; }
            set
            {
                cabangLayanansCV = value;
                NotifyPropertyChanged(cabangLayanansCVChangeArgs);
            }
        }

        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs cabangProduksChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.ProdukCabangs);
        public DispatcherNotifiedObservableCollection<CabangProdukThumbnailViewModel> ProdukCabangs
        {
            get { return cabangProduks; }
            set
            {
                cabangProduks = value;
                NotifyPropertyChanged(cabangProduksChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs cabangProduksCVChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.CabangProduksCV);
        public ICollectionView CabangProduksCV
        {
            get { return cabangProduksCV; }
            set
            {
                cabangProduksCV = value;
                NotifyPropertyChanged(cabangProduksCVChangeArgs);
            }
        }

        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs promosChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.Promos);
        public DispatcherNotifiedObservableCollection<PromoThumbnailViewModel> Promos
        {
            get { return promos; }
            set
            {
                promos = value;
                NotifyPropertyChanged(promosChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs promosCVChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.PromosCV);
        public ICollectionView PromosCV
        {
            get { return promosCV; }
            set
            {
                promosCV = value;
                NotifyPropertyChanged(promosCVChangeArgs);
            }
        }

        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs freeGiftsChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.FreeGifts);
        public DispatcherNotifiedObservableCollection<FreeGiftThumbnailViewModel> FreeGifts
        {
            get { return freeGifts; }
            set
            {
                freeGifts = value;
                NotifyPropertyChanged(freeGiftsChangeArgs);
            }
        }
        /// <summary>
        /// </summary>
        static PropertyChangedEventArgs freeGiftsCVChangeArgs =
            ObservableHelper.CreateArgs<CabangThumbnailViewModel>(x => x.FreeGiftsCV);
        public ICollectionView FreeGiftsCV
        {
            get { return freeGiftsCV; }
            set
            {
                freeGiftsCV = value;
                NotifyPropertyChanged(freeGiftsCVChangeArgs);
            }
        }
        #endregion

        #region Public.SummaryData
        #endregion

        #endregion

        #region Command Handlers
        /// <summary>
        /// </summary>
        private bool CanExecuteCabangRemoveCommand(Object args)
        {
            return !isBusy;
        }
        /// <summary>
        /// </summary>
        private void ExecuteCabangRemoveCommand(Object args)
        {
            Mediator.Instance.NotifyColleagues<CabangThumbnailViewModel>("TryRemoveCabangThumbnail", this);
        }
        #endregion

        #region Mediator Message Sinks
        //[MediatorMessageSink("SummaryChangeMessage")]
        //private void SummaryChangeMessage(Boolean dummy)
        //{
        //    NotifyPropertyChanged(subTotalHargaChangeArgs);
        //    NotifyPropertyChanged(totalPotonganChangeArgs);
        //    NotifyPropertyChanged(totalHargaChangeArgs);
        //    NotifyPropertyChanged(totalPembayaranChangeArgs);
        //    NotifyPropertyChanged(kembalianChangeArgs);
        //}
        #endregion

        #region Private Methods
        #endregion

        #region Overrides
        public override string ToString()
        {
            return String.Format("CabangThumbnailViewModel {0}", this.idCabang);
        }
        #endregion

        #region EditableValidatingViewModelBase overrides
        #endregion
    }
}
